import { reqRoleAuth, reqUpdateRoleAuth } from "@/api/acl/assign"

/* 
分配权限页面仓库
 */
const actions = {
    // 获取角色权限的action
    async getRoleAuth({ commit }, roleId) {
        const result = await reqRoleAuth(roleId)
        if (result.code === 20000) {
            commit('GETROLEAUTH', result.data.children)
        }
    },
    // 更新角色权限的action
    async updateRoleAuth(_, params) {
        const result = await reqUpdateRoleAuth(params)
        if (result.code === 20000) {
            return 'ok'
        }
        return Promise.reject()
    }
}
const mutations = {
    GETROLEAUTH(state, roleAuthList) {
        state.roleAuthList = roleAuthList
    },
    // 清空roleAuthList
    CLEAR(state) {
        state.roleAuthList = []
    }
}
const state = {
    roleAuthList: []
}

export default {
    namespaced: true,
    actions,
    mutations,
    state
}